package com.kantboot.util.common;


import java.math.BigInteger;

/**
 * 不一网络科技社的信息摘要类
 * @author 方奕丰
 */
public class BYMD {

    public static String to1(String str) {
        Integer strLen = str.length();
        BigInteger bi = new BigInteger("1");
        for (int i = 0; i < strLen; i++) {
            int sca = str.charAt(i) + 1;
            bi = bi
                    .multiply(BigInteger.valueOf(sca)).multiply(BigInteger.valueOf(sca))
                    .multiply(new BigInteger("8900101000071079809112830017968805202122120150786982002831090798107100010099891"))
                    .add(new BigInteger((i + 1) * sca + "")
                            .multiply(new BigInteger("8900101000071079809112830017968805202122120150786982002831090798107100010099891")));
        }
        String result = bi + "";
        result = result.substring(result.length() - strLen - 64, result.length() - strLen);
        return result;
    }

    public static char to2(String str) {
        int int1 = Integer.parseInt(str);
        if (int1 < 27) {
            int1 += 100;
            return (char) (int1);
        }

        if(int1>26&&int1<32){
            int1+=21;
            return (char) (int1);
        }

        if (int1==32){
            int1='S';
            return (char) (int1);
        }

        if(int1==34){
            int1='\'';
            return (char) (int1);
        }

        return (char) (int1);
    }

    public static String to3(String str){
        String result="";
        for (int i = 0; i < (str.length()/2); i++) {
           result+=to2(str.substring(i*2,i*2+2));
        }
        return result;
    }


    /**
     * 生成BGMD
     * @param str 生成BYMD的字符串
     * @return
     */
    public static String create(String str){
        return to3(to1(str));
    }

}
